#include <iostream>
#include <fstream>
#include <string>
#include <vector>
//#include "ALU_MUL.h"
//#include "ALU_DEF.h"
//#include "ALU_ADD.h"
//#include "LRF.h"
#include "ALU_CLUSTER.h"

using namespace std;

int main(void)
{
	// Start clock cycle count at zero
	int clockCycles = 0;
	
	// Open up code file and store instructions in vector
	ifstream microcode;
	string tempString;
	vector<string> instructions;

	microcode.open("code.imn", ifstream::in);
	if( microcode.is_open())
	{
		while( !microcode.eof())
		{
			getline(microcode, tempString);
			instructions.push_back(tempString);
		}

		microcode.close();
	}

	int inA, inB, outZ;
	float inFA, inFB, outFZ;

	ALU_CLUSTER* myCluster = new ALU_CLUSTER();
	LRF* myLRF = new LRF();

	myCluster->set_fu(ALU_ADD_FU, 0, 11, 0.0f, -12, 0.0f, IADD_OPCODE);
	myLRF->clear();

	ALU_MUL * myAdder = new ALU_MUL(); //Instantiate my adder

	// Set up first data and instruction
/*	myAdder->inputA = -15;
	myAdder->inputB = 16;
	myAdder->OpCode = IMUL_OPCODE;

	do
	{
		myAdder->update();
		clockCycles++;
	}
	while(!myAdder->isReady());

	cout << "Simulation Complete\n";
	cout << "Cycles run: " << clockCycles << endl;
	cout << "InputA: " << myAdder->inputA << endl;
	cout << "InputB: " << myAdder->inputB << endl;
	cout << "Result: " << myAdder->getOutput() << endl;

	myAdder->inputA = 15;
	myAdder->inputB = 16;
	myAdder->OpCode = UMUL_OPCODE;*/

	do
	{
		myCluster->update(ALU_ADD_FU, 0);
		clockCycles++;
	}
	while(!myCluster->isReady(ALU_ADD_FU, 0));
	myCluster->get_fu(ALU_ADD_FU, 0, inA, inFA, inB, inFB, outZ);


	cout << "Simulation Complete\n";
	cout << "Cycles run: " << clockCycles << endl;
	//cout << hex;
	cout << "InputA: " << inA << endl;
	cout << "InputB: " << inB << endl;
	cout << "Result: " << myCluster->getOutput(ALU_ADD_FU, 0) << endl;

	return 0;
}